﻿
// homework1View.cpp: Chomework1View 类的实现
//

#include "pch.h"
#include "framework.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义，并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "homework1.h"
#endif

#include "homework1Doc.h"
#include "homework1View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// Chomework1View

IMPLEMENT_DYNCREATE(Chomework1View, CView)

BEGIN_MESSAGE_MAP(Chomework1View, CView)
	// 标准打印命令
	ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &Chomework1View::OnFilePrintPreview)
	ON_WM_CONTEXTMENU()
	ON_WM_RBUTTONUP()
	ON_WM_LBUTTONDOWN()
	ON_WM_RBUTTONDOWN()
	ON_WM_RBUTTONDBLCLK()
	ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()

// Chomework1View 构造/析构

Chomework1View::Chomework1View() noexcept
	//:last_point(-1, -1)
{
	// TODO: 在此处添加构造代码
	points.reserve(8);
}

Chomework1View::~Chomework1View()
{
}

BOOL Chomework1View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: 在此处通过修改
	//  CREATESTRUCT cs 来修改窗口类或样式

	return CView::PreCreateWindow(cs);
}

// Chomework1View 绘图

void Chomework1View::OnDraw(CDC* pDC)
{
	Chomework1Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc || points.empty())
		return;
	// TODO: 在此处为本机数据添加绘制代码
	pDC->Polyline(&points[0], points.size());
	float_point = points[points.size() - 1];
}


// Chomework1View 打印


void Chomework1View::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
	AFXPrintPreview(this);
#endif
}

BOOL Chomework1View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// 默认准备
	return DoPreparePrinting(pInfo);
}

void Chomework1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 添加额外的打印前进行的初始化过程
}

void Chomework1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 添加打印后进行的清理过程
}

void Chomework1View::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
	ClientToScreen(&point);
	//OnContextMenu(this, point);
}

void Chomework1View::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
	theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}


// Chomework1View 诊断

#ifdef _DEBUG
void Chomework1View::AssertValid() const
{
	CView::AssertValid();
}

void Chomework1View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

Chomework1Doc* Chomework1View::GetDocument() const // 非调试版本是内联的
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(Chomework1Doc)));
	return (Chomework1Doc*)m_pDocument;
}
#endif //_DEBUG

// Chomework1View 消息处理程序
void Chomework1View::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if (!points.empty())
	{
		CClientDC dc(this);
		dc.MoveTo(points[points.size() - 1]);
		dc.LineTo(point);
	}
	float_point = point;
	points.push_back(point);
	CView::OnLButtonDown(nFlags, point);
}

void Chomework1View::OnRButtonDown(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	Invalidate();
	UpdateWindow();
	points.clear();
	CView::OnRButtonDown(nFlags, point);
}

void Chomework1View::OnMouseMove(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if (!points.empty())
	{
		CClientDC dc(this);
		dc.SetROP2(R2_NOTXORPEN);
		dc.MoveTo(points[points.size() - 1]);
		dc.LineTo(float_point);
		dc.MoveTo(points[points.size() - 1]);
		dc.LineTo(point);
		float_point = point;
	}
	CView::OnMouseMove(nFlags, point);
}
